
		set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

Alter TRIGGER [HeadingSetOnUpdate] 
   ON  [dbo].[HeadingSet] 
   AFTER Update
AS 
	declare @tablePrimaryKey CodeTypeType
	declare @UpdateBy nvarchar(50)
	declare @UpdateIP nvarchar(50)
	declare @UpdateDate datetime
	
	select @tablePrimaryKey = [HeadingSet] from inserted
	select @UpdateBy = [UpdateBy] from inserted
	select @UpdateIP = [UpdateIP] from inserted
	select @UpdateDate = [UpdateDate] from inserted
	

if (update([HeadingSet]))
 begin
  declare @NewHeadingSet CodeTypeType
  declare @OldHeadingSet CodeTypeType

  select @OldHeadingSet = [HeadingSet] from Deleted
  select @NewHeadingSet = [HeadingSet] from inserted
if( @OldHeadingSet != @NewHeadingSet)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('HeadingSet','HeadingSet',@tablePrimaryKey,@NewHeadingSet,@OldHeadingSet,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([HeadingSetName]))
 begin
  declare @NewHeadingSetName DescriptionType
  declare @OldHeadingSetName DescriptionType

  select @OldHeadingSetName = [HeadingSetName] from Deleted
  select @NewHeadingSetName = [HeadingSetName] from inserted
if( @OldHeadingSetName != @NewHeadingSetName)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('HeadingSetName','HeadingSet',@tablePrimaryKey,@NewHeadingSetName,@OldHeadingSetName,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([OwnerGroupID]))
 begin
  declare @NewOwnerGroupID GroupIDType
  declare @OldOwnerGroupID GroupIDType

  select @OldOwnerGroupID = [OwnerGroupID] from Deleted
  select @NewOwnerGroupID = [OwnerGroupID] from inserted
if( @OldOwnerGroupID != @NewOwnerGroupID)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('OwnerGroupID','HeadingSet',@tablePrimaryKey,@NewOwnerGroupID,@OldOwnerGroupID,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([IsDelete]))
 begin
  declare @NewIsDelete int
  declare @OldIsDelete int

  select @OldIsDelete = [IsDelete] from Deleted
  select @NewIsDelete = [IsDelete] from inserted
if( @OldIsDelete != @NewIsDelete)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('IsDelete','HeadingSet',@tablePrimaryKey,@NewIsDelete,@OldIsDelete,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

